Set Up Workspace


In [1]:
#%pylab inline
%pylab
import os
os.chdir('/Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM')
import KAM
reload(KAM)
from  datetime import date
import collections


Using matplotlib backend: MacOSX
Populating the interactive namespace from numpy and matplotlib

In [2]:
#cd /Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM
os.chdir('/Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM')

In [3]:
# import KAM
# reload(KAM)
# from  datetime import date
# import os

In [4]:
widths = np.array([2,4,8,16,32,64,128,256])
Z3 = np.array([85.77,67.82,50.176,33.82,21.24,12.72,7.18,3.58])
Z3_dict = dict(zip(widths,Z3))
Z1 = np.array([52.10,52.10,52.10,52.10,52.10,52.10,52.10,52.10])
Z1_dict = dict(zip(widths,Z1))
Eeff = np.array([4.196,3.8148,3.2517,2.6174,2.09048,1.7018,1.4482,1.2773])
Eeff_dict = dict(zip(widths,Eeff))

In [5]:
Ver = 1
%run -i Load_Datasets.py


Table metadata is missing Resonator_Eeff. Setting to None
Table metadata is missing Resonator_Impedance. Setting to None
Table metadata is missing Ground_Plane_Thickness. Setting to None
Table metadata is missing Feedline_Impedance. Setting to None
Table metadata is missing Electrical_Delay. Setting to None
Table metadata is missing Resonator_Thickness. Setting to None
Table metadata is missing Resonator_Width. Setting to None

In [6]:
#data extraction conditions for  power sweeps
#Power_Sweeps = [Run51aP,Run51bP,Run49aP ,Run48bP    , Run48aP  ,Run46aPl ,Run46aPh   ,Run45bP  ,Run45aP  ,Run44bP    ,Run44aP    ,Run52b1st  ,Run52b2nd]
condition =     ['Q>0'  ,'Q>0'  ,'Pr<-65','Qc<700000', 'Pr<-68' ,'Qc>0'   ,'(Q<210000)&(Qc>0)' ,'Pr<-45' ,'Pr<-60' ,'Qc<700000','Qc<200000','Q>0'   ,'Q>0'   ]
for sweep in xrange(len(Power_Sweeps)):
    Power_Sweeps[sweep].metadata.condition = condition[sweep]

In [7]:
#sort power sweep list so that narrowest resonator is first and widest is last
Power_Sweeps.sort(key = lambda w: w.metadata.width)

In [71]:
def Plot_Data_Sets(X_expression, Y_expression, Xlabel = None, Ylabel = None, Title = None, Save = False,Point_Label = True,Marker_Map = True,Yscale = 'linear', Xscale = 'linear' ):
    fig = plt.figure( figsize=(5,5), dpi=150)
    
    ax = fig.add_subplot(111)
    #norm = mpl.colors.Normalize(vmin=0, vmax=len(Power_Sweeps))
    norm = mpl.colors.Normalize(vmin=2, vmax=8)
    scalarMap = cm.ScalarMappable(norm=norm, cmap='gist_rainbow')
    count = collections.Counter()
    #markers = {1:',', 2:'x', 3:'+', 4:'1'}
    markers = {1:'1', 2:'2', 3:'3', 4:'4'}
    for sweep in xrange(len(Power_Sweeps)):
        if Power_Sweeps[sweep].metadata.custom[0] == True: #the show flag
            # If Power_Sweeps[sweep].metadata.condition references Pr, Q etc we will need to have these defined...
            width = Power_Sweeps[sweep].metadata.width
            Pr = Power_Sweeps[sweep].Sweep_Array['Preadout_dB'] 
            Qc = Power_Sweeps[sweep].Sweep_Array['Qc']
            Q =  Power_Sweeps[sweep].Sweep_Array['Q']
            Fr =  Power_Sweeps[sweep].Sweep_Array['Fr']
            Temp = Power_Sweeps[sweep].Sweep_Array['Temperature']
            Qi = 1.0/((1.0/Q)-(1.0/Qc))

            Pr_Volts_Peak = np.power(10,(Pr-10)/20) #Volts Peak
            Pr_Watts =  np.square(Pr_Volts_Peak)/(2*50)#watts
            Pint = 10*np.log10(Pr_Watts*Q*Q/(np.pi*Qc)) #dBm
            Imax = 2*Pr_Volts_Peak*Q/np.sqrt(np.pi*Z1_dict[width]*Z3_dict[width]*Qc) #Amps
            Jmax = Imax/(width*1e-6*200e-9)

            cond = eval(Power_Sweeps[sweep].metadata.condition)
            X_array = eval(X_expression)
            Y_array = eval(Y_expression)
            xdict = dict(zip(X_array,arange(X_array.size)))
            x = np.extract(cond,X_array)
            y = np.extract(cond,Y_array)
            if Marker_Map == True:
                count[str(Power_Sweeps[sweep].metadata.width)] +=1
                mark = markers[count[str(Power_Sweeps[sweep].metadata.width)]]
            else:
                mark ='.'
            line = ax.plot(x,y, color = scalarMap.to_rgba(np.log2(Power_Sweeps[sweep].metadata.width)), label = str(Power_Sweeps[sweep].metadata.width)+ '$\mu m$; Run '+ Power_Sweeps[sweep].metadata.Run + Power_Sweeps[sweep].metadata.custom[1], linewidth=3,linestyle= Power_Sweeps[sweep].metadata.custom[2], marker = mark,markeredgecolor = 'k',  markerfacecolor = 'k',markersize = 3 )        
            #line = ax.plot(x,y, color = scalarMap.to_rgba(sweep), label = str(Power_Sweeps[sweep].metadata.width)+ '$\mu m$; Run '+ Power_Sweeps[sweep].metadata.Run, linewidth=3,linestyle= '-', marker = '.', markerfacecolor = 'k' )
            if Point_Label == True:
                for i,j in zip(x,y):
                    if mod(xdict[i],5) == 0:
                        ax.annotate(str(xdict[i]),xy=(i,j), size = 4, rotation = 90,xytext=(i,j))
        
    ax.legend(loc = 'best', fontsize=5,scatterpoints =1, numpoints = 1, labelspacing = .02)
    #ax.set_ylim((-50000.0, 400000.0))
    #ax.set_ylim((0.0, 600000.0)) #for Qc
    #ax.set_xlim((-118.0, -20.0))
    ax.ticklabel_format(axis='y', style='sci',useOffset=False)
    ax.set_ylabel(Ylabel, color='k')
    ax.set_xlabel(Xlabel, color='k')
    ax.xaxis.labelpad = 10 #move the xlabel down a bit, also possible with ax.xaxis.set_label_coords(0.5, -0.1)
    ax.set_xscale(Xscale)
    ax.set_yscale(Yscale)
    ax.set_title(Title)
    plt.subplots_adjust(left=.2, bottom=0.13, right=None, top=None)
    ax.tick_params(axis='y', labelsize=9)
    ax.tick_params(axis='x', labelsize=9)
    ax.grid()
    plt.show()
    if Save == True:
        #loc = os.getcwd()
        #os.chdir(loc+os.sep+'Plots')
        loc = '/Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM'
        os.chdir('/Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM/Plots/')
        fig.savefig(Title.replace('\n','_').replace(' ','_')+'_'+date.today().strftime("%Y%m%d"),dpi=300, transparency  = True)
        os.chdir(loc)

Probe Power Plots


In [72]:
if 1: 
    Save = True
    Xlabel = 'Probe Power [dBm]'
    Ylabel = 'Internal Quality Factor, $Q_i$'
    Title = 'Effect of Probe Power on\nInternal Quality Factor'
    Plot_Data_Sets("Pr", "Qi", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False)

if 1:
    Save = False
    Xlabel = 'Probe Power [dBm]'
    Ylabel = 'Coupling Quality Factor, $Q_c$'
    Title = 'Effect of Probe Power on\nCoupling Quality Factor'
    Plot_Data_Sets("Pr", "Qc", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False)

if 0:
    Save = False
    Xlabel = 'Probe Power [dBm]'
    Ylabel = 'Loop Diameter, $Q/Q_c$'
    Title = 'Effect of Probe Power on\nLoop Diameter'
    Plot_Data_Sets("Pr", "Q/Qc", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False)

if 0:
    Save = False
    Xlabel = 'Probe Power [dBm]'
    Ylabel = r'Fractional Resonant Frequency Shift, $\delta f_r/f_r$'
    Title = 'Effect of Probe Power on\nResonance Frequency Shift'
    Plot_Data_Sets("Pr", "(Fr-Fr[0])/Fr[0]", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False)


-c:24: RuntimeWarning: invalid value encountered in log10
-c:25: RuntimeWarning: invalid value encountered in sqrt
-c:24: RuntimeWarning: invalid value encountered in log10
-c:25: RuntimeWarning: invalid value encountered in sqrt

In [9]:


In [9]:

Internal Power Plots


In [10]:
Save = False
Xlabel = r'Resonator Internal Power,  $\frac{Q^2\cdot P_{probe}}{Q_c \pi}$ [dBm]'
Ylabel = r'Internal Quality Factor $Q_i$'
Title = 'Internal Quality Factor versus\nInternal Power'
Plot_Data_Sets("Pint", "Qi", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False)


-c:23: RuntimeWarning: invalid value encountered in log10
-c:24: RuntimeWarning: invalid value encountered in sqrt

$I_{max}$ Plots


In [11]:
if 0:
    Save = False
    Xlabel = r'Resonator Max Current, $I_{max}$ [Amps]'
    Ylabel = r'Internal Quality Factor $Q_i$'
    Title = 'Internal Quality Factor versus\nMax Current'
    Plot_Data_Sets("Imax", "Qi", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current, $I_{max}$ [Amps]'
    Ylabel = r'Coupling Quality Factor $Q_c$'
    Title = 'Coupling Quality Factor versus\nMax Current'
    Plot_Data_Sets("Imax", "Qc", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current, $I_{max}$ [Amps]'
    Ylabel = r'Loop Diameter, $Q/Q_c$'
    Title = 'Loop Diameter versus\nMax Current'
    Plot_Data_Sets("Imax", "Q/Qc", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current, $I_{max}$ [Amps]'
    Ylabel = r'Quality Factor $Q$'
    Title = 'Quality Factor versus\nMax Current'
    Plot_Data_Sets("Imax", "Q", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current, $I_{max}$ [Amps]'
    Ylabel = r'Fractional Resonant Frequency Shift, $\delta f_r/f_r$'
    Title = 'Resonance Frequency Shift versus\nMax Current'
    Plot_Data_Sets("Imax", "(Fr-Fr[0])/Fr[0]", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False,Xscale = 'log')

$J_{max}$ Plots


In [12]:
if 0:
    Save = False
    Xlabel = r'Resonator Max Current Density,  $J_{max}$ [Amps/m^2]'
    Ylabel = r'Internal Quality Factor $Q_i$'
    Title = 'Internal Quality Factor versus\nMax Current Density'
    Plot_Data_Sets("Jmax", "Qi", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current Density,  $J_{max}$ [Amps/m^2]'
    Ylabel = r'Coupling Quality Factor $Q_c$'
    Title = 'Coupling Quality Factor versus\nMax Current Density'
    Plot_Data_Sets("Jmax", "Qc", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current Density,  $J_{max}$ [Amps/m^2]'
    Ylabel = r'Loop Diameter, $Q/Q_c$'
    Title = 'Loop Diameter versus\nMax Current Density'
    Plot_Data_Sets("Jmax", "Q/Qc", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current Density,  $J_{max}$ [Amps/m^2]'
    Ylabel = r'Quality Factor $Q$'
    Title = 'Quality Factor versus\nMax Current Density'
    Plot_Data_Sets("Jmax", "Q", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False, Xscale = 'log')

if 0:
    Save = False
    Xlabel = r'Resonator Max Current Density,  $J_{max}$ [Amps/m^2]'
    Ylabel = r'Fractional Resonant Frequency Shift, $\delta f_r/f_r$'
    Title = 'Resonance Frequency Shift versus\nMax Current Density'
    Plot_Data_Sets("Jmax", "(Fr-Fr[0])/Fr[0]", Xlabel = Xlabel, Ylabel = Ylabel, Title = Title, Save = Save, Point_Label = False,Xscale = 'log')

In [12]:


In [12]:


In [12]:


In [15]:
#fig = plt.figure( figsize=(5.5, 4.5), dpi=100)
fig = plt.figure( figsize=(5, 5), dpi=150)
ax = fig.add_subplot(111)
sweep = Run45aP
index = 0; line1 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-100 dBm Probe Power', linewidth=3,linestyle= '-')
index = 8; line2 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-72 dBm Probe Power', linewidth=3,linestyle= '-')
index = 11; line3 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-66 dBm Probe Power', linewidth=3,linestyle= '-')
#index = 18; line4 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-52 dBm Probe Power', linewidth=3,linestyle= '-')

#S21_log_dB = lambda Q,Qc,Fr: 

ax.set_xlabel('Frequency [MHz]',color = 'k')
#ax.xaxis.get_major_formatter().set_powerlimits((0, 1))
ax.ticklabel_format(axis='x', style='plain', scilimits=(0,0),useOffset=False)
ax.xaxis.set_major_locator(plt.LinearLocator(5))
ax.set_ylabel('$|S_{21}|$ [dB]', color='k')
ax.set_title('Trsansmission Around Resonance at Different Powers: \n\n 64 $\mu m$ wide Al microstrip on Nb ground plane, Run 45a', fontsize=9)
ax.legend(loc = 'best', fontsize=9) 
#ax.legend(loc = 'lower center', fontsize=9, bbox_to_anchor=(0.5, 0), ncol=2)
ax.grid()
plt.subplots_adjust(left=.15, bottom=.15, right=None, top=.85)
plt.show()

def Print_Quantities(index):
    sweep = Run45aP
    Q = sweep.Sweep_Array['Q'][index]
    Qc = sweep.Sweep_Array['Qc'][index]
    Qi = 1.0/((1.0/Q)-(1.0/Qc))
    Pr = sweep.Sweep_Array['Preadout_dB'][index] 
    print('Q = {0}; Qc = {1}; Qi = {2}; Pr = {3}'.format(Q, Qc,Qi,Pr))

Print_Quantities(0)
Print_Quantities(8)
Print_Quantities(11)


#fig.savefig('Transmission_at_Different_Powers', dpi = 300, transparency  = True)


Q = 145122.569784; Qc = 306239.342945; Qi = 275838.694788; Pr = -99.8813079567
Q = 116033.175729; Qc = 302183.11256; Qi = 188360.344349; Pr = -71.881292296
Q = 115003.51641; Qc = 354662.804729; Qi = 170189.396663; Pr = -65.8812729602

In [14]:
sweep = Run45aP
print(sweep.Sweep_Array['Pinput_dB'])
def plot_routine(index):
    sweep.pick_loop(index)
    sweep.decompress_gain(Compression_Calibration_Index = -1, Show_Plot = False, Verbose = False)
    sweep.remove_cable_delay(Show_Plot = False, Verbose = False) 
    sweep.circle_fit(Show_Plot = True) 
    sweep.phase_fit(Fit_Method = 'Multiple',Verbose = True, Show_Plot = True)
    print(sweep.loop.Phase_Fit_Method)
plot_routine(11)


[-55. -45. -40. -37. -35. -33. -31. -29. -27. -25. -23. -21. -19. -17. -15.
 -13. -11.  -9.  -7.]
Duplicates cuts:
	2 duplicate frequencies removed from loop data, 1598 remaining data points
Radius cut:
	1 points < r_loop*0.75 or > r_loop*1.75 found and removed, 1597 remaining data points
Bandwidth cut:
	0 points outside of fr_est +/- 8*FWHM_est removed, 1597 remaining data points
Angle jump cut:
	0 points with discontinuous jumps in loop angle removed, 1597 remaining data points
Initial Guess:
	Loop rotation 5.65789425035, fr 664758919.277, Q 122949.624189

Nelder-Mead Minimzation Result:
  status: 0
    nfev: 634
 success: True
     fun: 197.62349784459917
       x: array([  3.79211872e+00,   6.64759635e+08,   1.15003509e+05])
 message: 'Optimization terminated successfully.'
     nit: 289


Powell Minimzation Result:
  status: 0
 success: True
   direc: array([[ -2.91794072e-03,   2.13631909e+01,  -4.38476360e+02],
       [ -7.41155255e-02,   1.97373700e+01,  -2.23549890e+02],
       [  3.15870782e-07,  -3.35480171e-03,  -4.68944283e-01]])
    nfev: 963
     fun: 197.62349784468802
       x: array([  3.79211876e+00,   6.64759635e+08,   1.15003561e+05])
 message: 'Optimization terminated successfully.'
     nit: 7


Newton-CG Minimzation Result:
  status: 2
 success: False
    njev: 15
    nfev: 26
     fun: 291.89554965276966
       x: array([ 3.7055922,  6.6475892e+08,  122949.62], dtype=float128)
 message: 'Desired error not necessarily achieved due to precision loss.'
    nhev: 2
     jac: array([ 24281.608, -3.572282,  0.008196989], dtype=float128)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-bf9da19225aa> in <module>()
      8     sweep.phase_fit(Fit_Method = 'Multiple',Verbose = True, Show_Plot = True)
      9     print(sweep.loop.Phase_Fit_Method)
---> 10 plot_routine(11)

<ipython-input-14-bf9da19225aa> in plot_routine(index)
      7     sweep.circle_fit(Show_Plot = True)
      8     sweep.phase_fit(Fit_Method = 'Multiple',Verbose = True, Show_Plot = True)
----> 9     print(sweep.loop.Phase_Fit_Method)
     10 plot_routine(11)

AttributeError: loop instance has no attribute 'Phase_Fit_Method'

In [ ]:
Run45aP.metadata.LNA

In [ ]:


In [ ]: